package ${package.Service};

import ${cfg.parentPackage}.dao.${entity}DAO;
import ${package.Entity}.${entity};
import ${cfg.parentPackage}.domain.${entity}DO;
import ${cfg.parentPackage}.query.${entity}Query;
import com.hfepay.common.core.bean.Result;
import com.hfepay.common.data.mybatis.bean.QueryPage;
import com.hfepay.common.data.mybatis.util.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfepay.common.core.bean.Page;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.hfepay.common.util.BeanUtils;


import java.util.Map;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
public class ${table.serviceName}{
    @Autowired
    private ${entity}DAO ${table.entityPath}DAO;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    public Result<${entity}DO> selectById(Long id){
        return Result.success(BeanUtils.copyProperties(${table.entityPath}DAO.getById(id),${entity}DO.class));
    }

    /**
    * 根据ID删除
    * @param id
    * @return
    */
    public Result deleteById(Long id){
        return ${table.entityPath}DAO.removeById(id)?Result.success():Result.failure();
    }

    /**
    * 添加
    * @param ${table.entityPath}
    * @return
    */
    public Result insert(${entity} ${table.entityPath}){
        return ${table.entityPath}DAO.save(${table.entityPath})?Result.success():Result.failure();
    }

    /**
    * 修改
    * @param ${table.entityPath}
    * @return
    */
    public Result update(${entity} ${table.entityPath}){
        return ${table.entityPath}DAO.updateById(${table.entityPath})?Result.success():Result.failure();
    }

    /**
    * 统计总数
    *
    * @param query
    * @return
    */
    public Result<Integer> count(${entity}Query query) {
        return Result.success(${table.entityPath}DAO.count(this.combineQuery(query)));
    }

    /**
    * 列表查询
    * @param query
    * @return
    */
    public Result<List<${entity}DO>> list(${entity}Query query){
        return Result.success(BeanUtils.copyListProperties(${table.entityPath}DAO.list(this.combineQuery(query)),${entity}DO.class));
    }
    /**
    * 分页查询
    * @param page
    * @return
    */
    public Result<Page<${entity}DO>> page(QueryPage page, ${entity}Query query){
        return Result.success(PageHelper.newPage(${table.entityPath}DAO.page(page,this.combineQuery(query)),${entity}DO.class));
    }

    /**
    * 组装查询条件
    *
    * @param query
    * @return
    */
    private QueryWrapper<${entity}> combineQuery(${entity}Query query) {
        QueryWrapper<${entity}> wrapper = new QueryWrapper<>();
        //todo 查询条件 wrapper.eq("字段名","值")
        return wrapper;
    }

}







